<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <p>
            你好 <span id="name">zixuan</span>
        </p>
    </div>
    <script>
        const obj = {}
        Object.defineProperty(obj,"name",{
            get(){
                console.log('获取name的值');
                // 获取obj.name会触发，显示当前函数返回值
                return document.querySelector('#name').innerHTML
            },
            set(name){
                // obj.name = "xx" 会触发
                console.log('修改name属性');
                document.querySelector('#name').innerHTML = name
            }
        })
        console.log(obj.name);        
    </script>
</body>

</html>